<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * @var \Illuminate\Http\Request 请求实例
     */
    public $request;

    /**
     * 构造
     *
     * @param Request $request
     * 自身不处理任何初始化工作，转发初始化代理函数
     */
    public function __construct(Request $request)
    {
        // 注入请求对象
        $this->request = $request;

        // 转发初始化代理函数
        $this->_initialize();
    }

    /**
     * 初始化代理
     * 控制器初始化函数
     */
    public function _initialize()
    {
        /* ------------ 初始化逻辑代码 Start ------------ */

        /* ------------ 初始化逻辑代码 End ------------ */
    }

    /**
     * 获取请求参数
     *
     * @param string $name    参数名称
     * @param mixed  $default 默认值
     *
     * @return string|array|null
     */
    public function input($name = null, $default = null)
    {
        if ($name) {
            return $this->request->input($name, $default);
        }
        return $this->request->all();
    }
}
